define(() => {
    return function (cont, res) {
        $(".pagination").pagination(res.length, {
            items_per_page: 8,
            elipse_text: '...',
            current_page: 0,
            num_edge_entries: 2,
            prev_text: '上一页',
            next_text: '下一页',
            prev_show_always: true,
            next_show_always: false,
            callback: function (abc) {
                createList(abc, res);
            }
        })
    }
    function createList(index, res) {
        let str = "";
        for (let i = index * 8; i < (index + 1) * 8; i++) {
            if (i < res.length) {
                str += `
        <div class="list">
        <a href="./detail.html?id=${res[i].imgId}">
        
        <img src="${res[i].img}" art="">
        ￥：<span>${res[i].price}</span>
        韩元：<span>${res[i].money}</span></a>
        <span><button data-id="${res[i].imgId}" class="add">购物车</button></span>
        </div>`
            }

        }
        $(".Product").html(str);
        console.log($('.add'))
        if (localStorage.getItem("token")) {
            let user = `<a href="">${localStorage.username}</a>`;
            // console.log(user)
            $('.user').html(user)
            let exit = '`<a href="" id="exit">退出</a>`'
            $('.exit').html(exit)
            $('#exit').click(function () {
                localStorage.clear();
                location.href = 'index.html'
            })
        }
        $('.add').click(function () {
            if (!localStorage.getItem("token")) {
                alert("没有登陆，去登录")
                location.assign("http://localhost:3000/login.html")
                // location.href = './login.html'
            }
            // else {
            //     location.assign("http://localhost:3000/cart.html")
            // }
        })
    }
})

